#include "RungeKutta4.h"

RungeKutta4::RungeKutta4(ptoF paso,Funcion *f,ptoF u0){
	this->ultimoValor=u0;
	this->paso=paso;
	this->funcion=f;
	this->t=0;
}

RungeKutta4::~RungeKutta4()
{
}

ptoF RungeKutta4::iterar()
{
	ptoF q1=(this->paso)*(this->funcion->evaluar(this->ultimoValor,t));
	t+=(this->paso/2.0);
	ptoF q2=(this->paso)*(this->funcion->evaluar(this->ultimoValor+(q1/2.0),t));
	ptoF q3=(this->paso)*(this->funcion->evaluar(this->ultimoValor+(q2/2.0),t));
	t+=(this->paso/2.0);
	ptoF q4=(this->paso)*(this->funcion->evaluar(this->ultimoValor+q3,t));
	q1=this->ultimoValor+(((q1)+(2*q2)+(2*q3)+(q4))/6);
	this->ultimoValor=q1;
	return q1;
}
